<?php
/**
 * Created By Project
 * Author: 陈东
 * Copyright：陈东
 * Source Code：陈东
 * Explain：I shall not authorize for any other commercial purposes, law breakers must be prosecuted.
 */
namespace Home\Controller;
use Think\Controller;
use Home\Model\BnModel;

/*
 * 说明：根据ismobile()此函数判断是否是移动端
 * 返回：bool
 */
class BnController extends Controller {

	//实例化模型对象
	protected function newmodle(){
		return new BnModel();
	}

	/*
	 * 手机,PC端区分
	 */
	public function index(){
		$bn = $this->newmodle();
		if(ismobile()){ 
		 //移动端首页
			$id = I('get.id');//类型id
			$typelist = $bn::gettype();
			$this->assign('typelist',$typelist);
		   if(($id != null) ? $id = $id : $id =4){
			 $mblist  = $bn::getlisttotypeid($id);
			 $this->assign('mblist',$mblist);
			}
			$this->display('Bn/mobile/index');	
		}else{ 
		 //PC端首页
			$typelist = $bn::gettype();
			$listdetail = $bn::getlist();
			$this->assign('typelist',$typelist);
			$this->assign('listdetail',$listdetail);
			$this->display();
		}
	}

    public function ajaxIndex(){ 
    	//分类id
		$id = I('post.typeid');
		$bn = $this->newmodle();
		if(ismobile()){
		   if(($id != null) ? $id = $id : $id =1){
			 $mblist  = $bn::getlisttotypeid($id);
			 echo W('Dbn/gethrbnlist',array('res'=>$mblist));
			}
		}
    }

	
	
	protected function weixinshare(){
		include('jssdk.php');
		$jssdk = new \JSSDK("wx30934416968cbcb7", "2a1dabeb57ac5688b33117d29f6ec062");
		$signPackage = $jssdk->GetSignPackage();
		return $signPackage;
		//$this->assign('signPackage',$signPackage);
	}


	//详情页面
	public function atcvido(){
		$id = I('get.id');//类型id
		$bn = $this->newmodle();
		$atcdail = $bn::getinfotovid($id);
		$this->assign('atcdail',$atcdail);
		
		$ad = D('bnad');
		$res = $ad->find(1);
		$this->assign('ad',$res);
		
		if(ismobile()){ 
			/*微信分享*/
			$m_signPackage = $this->weixinshare();
			$this->assign('signPackage',$m_signPackage);
			$this->display('Bn/mobile/video');
		}else{
			$this->display('article');
		}
	}
	//手机端标题模糊搜索
	public function searchAll(){
		$searchTitle = I('post.searchTitle');//标题搜索
		$where['state'] = 1;
        $where['year'] = 2017;
		//$where['bn_zhiwei|bn_name'] = array('LIKE',"%".$searchTitle."%");
		$where['bn_name'] = array('LIKE',"%".$searchTitle."%");
		$condition['allcontent'] = $searchTitle;
		$bntitle = M('bn');
		$res = $bntitle->where($where)->select();
		if(ismobile()){
			$this->assign('mblist',$res);
			$this->assign('condition',$condition);
			$this->display('Bn/mobile/index');	
		}else{
			//获取类型id
			$id = I('post.typeid');
			$bn = $this->newmodle();
			//根据类型id查询对应的类型背景图片
			//$typeres = $bn::gettypetotypeid($id);
			$typelist = $bn::gettype();
			$this->assign('typelist',$typelist);
			$this->assign('listdetail',$res);
			//$this->assign('typeres',$typeres);
			$this->assign('condition',$condition);
			$this->display('index');	
		}
	}

	//大拜年手机端:标题模糊搜索(调用ajax显示数据)
	/*public function searchAll(){
		$searchTitle = I('post.searchTitle');//标题搜索
		$where['state'] = 1;
        $where['year'] = 2017;
        if(!empty($searchTitle)){
          $where['bn_title|bn_name'] = array('LIKE',"%".$searchTitle."%");
		  $condition['allcontent'] = $searchTitle;
        }
		$bntitle = M('bn');
		$res = $bntitle->where($where)->select();
		//echo $bntitle->getlastsql();
		echo W('Dbn/gethrbnlist',array('res'=>$res));
	}*/

	//大拜年PC列表页
	public function listdetail(){ 
		$id = I('get.id');//类型id
		$bn = $this->newmodle();
		if(!empty($id)){
			$typelist = $bn::gettype();
			$listdetail = $bn::getlisttotypeid($id);
		 }else{
		 	$typelist = $bn::gettype();
		 	$listdetail = $bn::getlist();
		 }
	    if(ismobile()){
			$this->assign('typelist',$typelist);
			$this->assign('mblist',$listdetail);
			$this->display('Bn/mobile/index');	
		}else{
		    $this->assign('typelist',$typelist);
		    $this->assign('listdetail',$listdetail);
		    $this->display('index');//大拜年列表页
		}
	}
	
	//分类页
	public function type($id){

		$bn = $this->newmodle();
		if($bn::isNum($id)){
			$typeres = $bn::gettypetotypeid($id);
			$datares = $bn::getlisttotypeid($id);
			$this->assign('typeres',$typeres);
			$this->assign('datares',$datares);
			$this->display();
		}else{
			die('非法参数');
		}
	}

	/*
	 * 视频资源
	 * 注：模板中获取视频地址字段为video
	 */
	public function article($id){

		$bn = $this->newmodle();
		if($bn::isNum($id)){
			$videoinfo = $bn::getinfotovid($id);
			$typeinfo = $bn::gettypetotypeid($videoinfo['type_id']);
			$this->assign('typeinfo',$typeinfo);
			$this->assign('videoinfo',$videoinfo);
			$bn::visit($id);
			$this->display();
		}else{
			die('非法参数');
		}
	}

}